package com.cn.sl.server.api.system.menu.model.entity

import com.cn.sl.server.api.system.menu.model.enumerate.MenuType
import com.cn.sl.server.api.system.role.model.entity.RoleEntity
import com.cn.sl.server.api.system.user.model.entity.AdminUserEntity
import com.cn.sl.server.common.model.EditableEntity
import io.hypersistence.utils.hibernate.type.json.JsonType
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.FetchType
import jakarta.persistence.ManyToMany
import jakarta.persistence.Table
import org.hibernate.annotations.Type

@Table(name = "menu")
@Entity
class MenuEntity : EditableEntity<AdminUserEntity>() {
    /**
     * name
     */
    var name: String = ""

    /**
     * path
     */
    var path: String = ""


    /**
     * 父级id
     */
    var parentId: Long? = null

    /**
     * 组件
     */
    var component: String? = ""

    /**
     * 重定向地址
     */
    var redirect: String? = ""

    /**
     * 菜单类型
     */
    @Enumerated(EnumType.STRING)
    var type: MenuType = MenuType.MENU

    /**
     * 扩展属性
     */
    @Type(JsonType::class)
    @Column(name = "meta", columnDefinition = "json")
    var meta: Map<String, Any> = hashMapOf()

    @ManyToMany(fetch = FetchType.EAGER, mappedBy = "menus")
    var roles: List<RoleEntity> = arrayListOf()
}